﻿using SLNGP.Common.Extensions;
using SLNGP.Core.GeneticPrograms;
using SLNGP.Core.Individuals;
using SLNGP.Core.SecondaryStrategies;

namespace SLNGP.Core.GeneticOpearators
{
    /// <summary>
    /// Sample selection. Ignore Fitness completely.
    /// </summary>
    public class RandomIgnoreFitnessSelection : SelectionGeneticOpearator
    {
        public RandomIgnoreFitnessSelection(int crossoverPercentage, int mutationPercentage, int carryUnchangedPercentage, int killPercentage) 
            : base(crossoverPercentage, mutationPercentage, carryUnchangedPercentage, killPercentage)
        {
        }

        public override void Execute()
        {
            foreach (IIndividual individual in Parent.LastRunResults.LastGeneration)
            {
                int random = Parent.GetStrategy<IRandomProvider>().Random(1, 100);
                if (random > 0 && random < CrossoverPercentage)
                    individual.SelectionMarker = SelectionMarkers.Crossover;
                else if (random > CrossoverPercentage && random < (CrossoverPercentage + MutationPercentage))
                    individual.SelectionMarker = SelectionMarkers.Mutation;
                else if (random > (CrossoverPercentage + MutationPercentage) && random < (CrossoverPercentage + MutationPercentage + CarryUnchangedPercentage))
                    individual.SelectionMarker = SelectionMarkers.CarryToNextGenerationUnchanged;
                else
                    individual.SelectionMarker = SelectionMarkers.Kill;
            }
        }

    }
}